package com.supermap.pisaclient.mine;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.supermap.pisaclient.R;
import com.supermap.util.base.BaseFragment;
import com.supermap.util.util.ToastUtil;
import com.supermap.util.view.ViewInject;
import com.supermap.util.view.ViewUtils;
import com.supermap.util.weather.ACache;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;



/**
 * Copyright (C) 2017 北京超图软件股份有限公司 版权所有
 * <p>
 * 功能描述：我的  作者：李会林
 * <p>
 * 修改人： 修改描述： 修改日期
 */
public class MineFragment extends BaseFragment {

    @ViewInject(R.id.user_menu)
    private ListView user_menu;
    @ViewInject(R.id.exit)
    private Button exit;
    @ViewInject(R.id.user_lan)
    private LinearLayout user_lan;
    private SimpleAdapter adapter;
    List<HashMap<String, Object>> data;
    Intent intent;
    private ACache mCache;
    int[] head_image = new int[]{R.drawable.focus, R.drawable.custom, R.drawable.change, R.drawable.shop, R.drawable.money, R.drawable.about};
    String[] menu_name = new String[]{"我的关注", "我的定制", "修改密码", "购物车", "智慧点", "关于"};

    public View getContainerView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.activity_mine, null);
        ViewUtils.inject(this,view);
        return view;
    }

    private void initViews() {
        exit.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                ToastUtil.showCustomViewToast(mContext,"退出登录成功");
            }
        });

        user_lan.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                intent = new Intent(getActivity(), PersonInfoActivity.class);
                startActivity(intent);
            }
        });

        user_menu.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_MOVE:
                        return true;
                    default:
                        break;
                }
                return false;
            }
        });

        data = new ArrayList<HashMap<String, Object>>();

        for(int i = 0; i <head_image.length; i++){
            HashMap<String, Object> map1 = new HashMap<String, Object>();
            map1.put("head_image", head_image[i]);
            map1.put("menu_name", menu_name[i]);
            map1.put("into", R.drawable.right);
            data.add(map1);
        }

        adapter = new SimpleAdapter(getContext(), data, R.layout.user_menu_listitem,
                new String[] { "head_image", "menu_name" ,"into"},
                new int[] { R.id.head_image, R.id.menu_name, R.id.into});

        user_menu.setAdapter(adapter);

        user_menu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if( position == 0 ){
                    intent = new Intent(getActivity(), TestActivity.class);
                    startActivity(intent);
                }
//                 else if( position == 1 ){
//                    intent = new Intent(WelcomeActivity.this, ChangepwActivity.class);
//                    startActivity(intent);
//                } else if( position == 3 ){
//                    intent = new Intent(WelcomeActivity.this, MyCustomActivity.class);
//                    startActivity(intent);
//                } else if( position == 6 ){
//                    intent = new Intent(WelcomeActivity.this, AboutActivity.class);
//                    startActivity(intent);
//                }
            }
        });
    }

    @Override
    public void initData() {
        initViews();
    }
}
